//
//  DYJiudianDetailCell.swift
//  SheYangBigData
//
//  Created by 宋海胜 on 2021/1/11.
//  Copyright © 2021 叁拾叁. All rights reserved.
//



import UIKit

class DYJiudianDetailCell: SYBaseCell , UITableViewDelegate, UITableViewDataSource {
    
    var contents: [String] = ["入住时间：12:00以后，12:30以前", "儿童及加床", "酒店允许携带儿童入住。", "12岁及以上客人视为成人。", "每间客房最多容纳1名11岁及以下儿童", "酒店允许携带儿童入住。", "宠物", "不可携带宠物。"]//，和成人共用现有床铺。
    var tableView: UITableView!
    var rowNum: Int = 8
    var sectionNum: Int = 2
    var bgView: UIView = {
        let v: UIView = UIView()
        v.backgroundColor = UIColor(hex: 0x367FF6)
        v.layer.cornerRadius = 2
        return v
    }()
    
    let nameLb: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0x1E1E1E)
        v.font = 17.autoBoldFontSize()
        v.text = "酒店详情"
        return v
    }()
    
    var sepView: UIView = {
        let v: UIView = UIView()
        v.backgroundColor = Constant.bgViewColor
        return v
    }()

    public func configureView() {
        
    }
    
    override func initViews() {
        
        var totalHeight: Double = 0.0
        contents.forEach { (value) in
            let height = value.getSize(font: UIFont.systemFont(ofSize: 13), maxSize: CGSize(width: SCREEN_WIDTH - 38, height: SCREEN_HEIGHT)).height
            if height > 17 {
                totalHeight += Double(height) + 14
            } else {
                totalHeight += 30.0
            }
        }
        totalHeight += 40.0 * Double(sectionNum)
        totalHeight += 30.0
        
        setTableView()
        contentView.addSubview(nameLb)
        contentView.addSubview(bgView)
        contentView.addSubview(tableView)
        contentView.addSubview(sepView)
        bgView.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(16.0.autoWidth())
            make.left.equalToSuperview().offset(autoWidth(14.5))
            make.width.equalTo(4.0.autoWidth())
            make.height.equalTo(15.0.autoWidth())
        }
        nameLb.snp.makeConstraints { (make) in
            make.centerY.equalTo(bgView)
            make.left.equalTo(bgView.snp.right).offset(autoWidth(7.0))
            make.right.equalToSuperview().offset(autoWidth(-15.0))
            make.height.equalTo(16.0.autoWidth())
        }
        tableView.snp.makeConstraints { (make) in
            make.top.equalTo(nameLb.snp.bottom).offset(autoWidth(10.0))
            make.left.right.equalToSuperview()
            make.height.equalTo(totalHeight)
            make.bottom.equalToSuperview().offset(-16.autoWidth())
        }
        sepView.snp.makeConstraints { (make) in
            
            make.left.right.equalToSuperview()
            make.height.equalTo(10.0.autoWidth())
            make.bottom.equalToSuperview()
        }
    }
    
    func setTableView() {
        
        //创建表格视图
        self.tableView = UITableView(frame: CGRect.zero, style:.plain)
        self.tableView.separatorStyle = .none
        self.tableView.delegate = self
        self.tableView.dataSource = self
//        self.tableView.isScrollEnabled = false
        self.tableView!.register(DYJiudianDetailSubCell.self, forCellReuseIdentifier: "Cell")
        self.contentView.addSubview(self.tableView!)
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if section == 0 {
            return 1
        }
        return rowNum
    }
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return sectionNum
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell: DYJiudianDetailSubCell? = tableView.dequeueReusableCell(withIdentifier: "Cell") as? DYJiudianDetailSubCell
        cell?.selectionStyle = .none
        if indexPath.section == 0 {
            cell?.nameLb.text = contents[indexPath.row]
            cell?.type = .black
        } else {
            cell?.nameLb.text = contents[indexPath.row]
            cell?.type = .gray
        }
        return cell!
    }
    
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        if section == 0 {
            let bidu = DYJiuDianBiduView(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: 40))
            return bidu
        } else {
            let zhengce = DYJiuDianZhengceView(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: 40))
            return zhengce
        }
    }
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        if section == 0 {
            return 40
        } else {
            return 40
        }
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        print("tableView000000000000000000000")
    }
}

